#include "Devii.h"

#include "float3.h"

#include "TextureEffect.h"
namespace devii
{

Devii::Devii()
{
	render_target = 0;
	depth_buffer = 0;
}

Devii::~Devii()
{
	shutdown();
}

bool Devii::startup(const int & width, const int & height, HWND hwnd)
{
	pipeline = new Pipeline();
	pipeline->startupD3D(width, height, hwnd);

	VertexBuffer * b = pipeline->createVertexBuffer();
	TriangleEffect* effect = new TriangleEffect(pipeline);
	triangle.init(b, effect);
	effect_factory.addEffect(effect);
	render_target = pipeline->createScreenRenderTarget(width, height);
	RenderTarget* rt = pipeline->createScreenRenderTarget(width, height);

	depth_buffer = pipeline->createDepthBuffer(width, height);
	Texture * texture = pipeline->createTexture(width, height, DXGI_FORMAT_R8G8B8A8_UINT);
	float color[4] = { 1.0f, 0.0f, 0.0f, 1.0f};

	pipeline->clearRenderTarget(color, render_target);
	pipeline->setRenderTarget(1, &render_target,depth_buffer);


	TextureEffect texture_effect = TextureEffect(pipeline);
	texture_effect.init(NULL);
	box = new Texture2D();

	box->init(&texture_effect);


	matrix temp;
	box->prepare(temp);

	return true;
}

bool Devii::shutdown()
{
	pipeline->shutdown();
	delete pipeline;
	pipeline = NULL;

	return true;
}

void Devii::render()
{

	float color[4] = { 1.0f, 1.0f, 0.0f, 1.0f};

	pipeline->clearRenderTarget(color, render_target);

	pipeline->clearDepthBuffer(depth_buffer);
	pipeline->setVertexBuffer(triangle.getVertexBuffer());
	triangle.prepare();

	pipeline->draw(0, 3);
	pipeline->swap();
}

}